import {defineStore} from 'pinia' //引入pinia
import router from '../../router/routerindex.js'
//这里官网是单独导出  是可以写成默认导出的  官方的解释为大家一起约定仓库用use打头的单词 固定统一小仓库的名字不易混乱
export const useStoreLogin = defineStore("Login", {
  state: () => {
    return ({
      showEdit: false,
      editTitle: '添加',
      showModel: true,
      swiperActive: 1,
      formmodel: {
        account: "admin",
        password: "123456",
        specialty: "1",
      }
    })
  },
  actions: {
    async login() {
      let res = await $api.login.login(this.formmodel);
      // console.log(res);
      if (res.code == 0) {
        $utilscommon.toast(res.message, 2, '登录错误！！！');
      } else {
        $utilstoken.setToken(res.data.token);
        $utilstoken.setStorage('sysuser', res.data)
        $utilstoken.setStorage('sysrole', res.data.sysrole)
        $utilstoken.setStorage('sysusermenus', res.data.sysmenu);
        // // console.log(router);
        router.push('/admin');
      }
    }
  },
})
